﻿using System;
using System.Collections;
using System.Collections.Generic;


namespace Petra.Gis.Support
{

  /// <summary>
  /// Represents a collection of keys and values.
  /// </summary>
  /// <typeparam name="TKey">The type of the keys in the dictionary.</typeparam>
  /// <typeparam name="TValue">The type of the values in the dictionary.</typeparam>
  public class DictionaryPlus<TKey, TValue> : IDictionary<TKey, TValue>
  {

    protected Dictionary<TKey, TValue> _dictionary;

    
    public DictionaryPlus()
    {
      _dictionary = new Dictionary<TKey, TValue>();
    }






    /// <summary>
    /// Returns an enumerator that iterates through the 
    /// System.Collections.Generic.Dictionary<TKey,TValue>.
    /// </summary>
    /// <returns>A System.Collections.Generic.Dictionary<TKey,TValue>.Enumerator structure for the 
    /// System.Collections.Generic.Dictionary<TKey,TValue>.</returns>
    public virtual System.Collections.Generic.IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
    {
      return _dictionary.GetEnumerator();
    }





    IEnumerator IEnumerable.GetEnumerator()
    {
      return GetEnumerator();
    }





    /// <summary>
    /// Adds the specified key and value to the dictionary.
    /// </summary>
    /// <param name="key">The key of the element to add.</param>
    /// <param name="value">The value of the element to add. 
    /// The value can be null for reference types.</param>
    public virtual void Add(TKey key, TValue value)
    {
      _dictionary.Add(key, value);
    }





    /// <summary>
    /// Removes the value with the specified key from the System.Collections.Generic.Dictionary<TKey,TValue>.
    /// </summary>
    /// <param name="key">The key of the element to remove.</param>
    /// <returns>true if the element is successfully found and removed;
    /// otherwise, false. This method returns false if key is not found in the
    /// System.Collections.Generic.Dictionary<TKey,TValue>.</returns>
    public virtual bool Remove(TKey key)
    {
      return _dictionary.Remove(key);
    }





    /// <summary>
    /// Removes the first occurrence of a specific object from the
    /// System.Collections.Generic.ICollection<T>.
    /// </summary>
    /// <param name="item">The object to remove from the 
    /// System.Collections.Generic.ICollection<T>.</param>
    /// <returns>true if item was successfully removed from the 
    /// System.Collections.Generic.ICollection<T>; otherwise, false. 
    /// This method also returns false if item is not found in the original
    /// System.Collections.Generic.ICollection<T>.</returns>
    public virtual bool Remove(System.Collections.Generic.KeyValuePair<TKey, TValue> item)
    {
      return ((System.Collections.Generic.ICollection<KeyValuePair<TKey, TValue>>)_dictionary).Remove(item);
    }





    /// <summary>
    /// opies the elements of the System.Collections.Generic.ICollection<T> 
    /// to an System.Array, starting at a particular System.Array index.
    /// </summary>
    /// <param name="array">The one-dimensional System.Array that is the destination 
    /// of the elements copied from System.Collections.Generic.ICollection<T>. 
    /// The System.Array must have zero-based indexing.</param>
    /// <param name="arrayIndex"></param>
    public virtual void CopyTo(System.Collections.Generic.KeyValuePair<TKey, TValue>[] array, int arrayIndex)
    {
      ((System.Collections.Generic.ICollection<KeyValuePair<TKey,TValue>>)_dictionary).CopyTo(array, arrayIndex);
    }





    /// <summary>
    /// Gets the number of key/value pairs contained in the 
    /// System.Collections.Generic.Dictionary<TKey,TValue>.
    /// </summary>
    public virtual int Count
    { 
      get
      {
        return _dictionary.Count;
      }
    }





    /// <summary>
    /// Determines whether the System.Collections.Generic.ICollection<T> 
    /// contains a specific value.
    /// </summary>
    /// <param name="item">The object to locate in the 
    /// System.Collections.Generic.ICollection<T>.</param>
    /// <returns>true if item is found in the 
    /// System.Collections.Generic.ICollection<T>; otherwise, false.</returns>
    public virtual bool Contains(System.Collections.Generic.KeyValuePair<TKey, TValue> item)
    {
      return ((System.Collections.Generic.ICollection<KeyValuePair<TKey, TValue>>)_dictionary).Contains(item);
    }





    /// <summary>
    /// Determines whether the System.Collections.Generic.Dictionary<TKey,TValue>
    /// contains the specified key.
    /// </summary>
    /// <param name="key">The key to locate in the System.Collections.Generic.Dictionary<TKey,TValue>.</param>
    /// <returns>true if the System.Collections.Generic.Dictionary<TKey,TValue> 
    /// contains an element with the specified key; otherwise, false.</returns>
    public virtual bool ContainsKey(TKey key)
    {
      return _dictionary.ContainsKey(key);
    }





    /// <summary>
    /// Determines whether the System.Collections.Generic.Dictionary<TKey,TValue>
    /// contains a specific value.
    /// </summary>
    /// <param name="value">The value to locate in the
    /// System.Collections.Generic.Dictionary<TKey,TValue>.
    /// The value can be null for reference types.</param>
    /// <returns>true if the System.Collections.Generic.Dictionary<TKey,TValue>
    /// contains an element with the specified value; otherwise, false.</returns>
    public virtual bool ContainsValue(TValue value)
    {
      return _dictionary.ContainsValue(value);
    }





    /// <summary>
    /// Gets the value associated with the specified key.
    /// </summary>
    /// <param name="key">The key of the value to get.</param>
    /// <param name="value">When this method returns,
    /// contains the value associated with the specified key,
    /// if the key is found; otherwise, the default value
    /// for the type of the value parameter.
    /// This parameter is passed uninitialized.</param>
    /// <returns>true if the System.Collections.Generic.Dictionary<TKey,TValue>
    /// contains an element with the specified key; otherwise, false.</returns>
    public virtual bool TryGetValue(TKey key, out TValue value)
    {
      return _dictionary.TryGetValue(key, out value);
    }





    /// <summary>
    /// Gets a value indicating whether the System.Collections.Generic.ICollection<T> is read-only.
    /// </summary>
    public virtual bool IsReadOnly
    {
      get
      {
        return false;
      }
    }






    /// <summary>
    /// Gets a collection containing the keys in the System.Collections.Generic.Dictionary<TKey,TValue>.
    /// </summary>
    public virtual System.Collections.Generic.ICollection<TKey> Keys
    {
      get
      {
        return _dictionary.Keys;
      }
    }





    /// <summary>
    /// Gets a collection containing the values in the System.Collections.Generic.Dictionary<TKey,TValue>.
    /// </summary>
    public virtual System.Collections.Generic.ICollection<TValue> Values
    {
      get
      {
        return _dictionary.Values;
      }
    }






    /// <summary>
    /// Gets or sets the value associated with the specified key.
    /// </summary>
    /// <param name="key">The key of the value to get or set.</param>
    /// <returns>The value associated with the specified key.
    /// If the specified key is not found, 
    /// a get operation throws a System.Collections.
    /// Generic.KeyNotFoundException, and a set operation creates 
    /// a new element with the specified key.</returns>
    public virtual TValue this[TKey key]
    {
      get 
      {
        return _dictionary[key];
      }
      set
      {
        _dictionary[key] = value;
      }
    }






    /// <summary>
    /// Removes all keys and values from the System.Collections.Generic.Dictionary<TKey,TValue>.
    /// </summary>
    public virtual void Clear()
    {
      _dictionary.Clear();
    }





    /// <summary>
    /// Adds an item to the System.Collections.Generic.ICollection<T>.
    /// </summary>
    /// <param name="item">The object to add to the System.Collections.Generic.ICollection<T>.</param>
    public virtual void Add(System.Collections.Generic.KeyValuePair<TKey, TValue> item)
    {
      _dictionary.Add(item.Key, item.Value);
    }



  }
}
